Crate http_cache_reqwest
source ·Expand description
The reqwest middleware implementation for http-cache.
use reqwest::Client;
use reqwest_middleware::{ClientBuilder, Result};
use http_cache_reqwest::{Cache, CacheMode, CACacheManager, HttpCache, HttpCacheOptions};
#[tokio::main]
async fn main() -> Result<()> {
let client = ClientBuilder::new(Client::new())
.with(Cache(HttpCache {
mode: CacheMode::Default,
manager: CACacheManager::default(),
options: HttpCacheOptions::default(),
}))
.build();
client
.get("https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching")
.send()
.await?;
Ok(())
}
Overriding the cache mode
The cache mode can be overridden on a per-request basis by making use of the
reqwest-middleware
extensions system.
client.get("https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching")
.with_extension(CacheMode::OnlyIfCached)
.send()
.await?;
Structs
- Error type for request parsing failure
- CACacheManager
manager-cacache
ImplementsCacheManager
withcacache
as the backend. - Wrapper for
HttpCache
- Configuration options which control behavior of the cache. Use with
CachePolicy::new_options()
. - Caches requests according to http spec.
- Can be used to override the default
CacheOptions
and cache key. The cache key is a closure that takeshttp::request::Parts
and returns aString
. - A basic generic type that represents an HTTP response
- MokaCache
manager-moka
A thread-safe, futures-aware concurrent in-memory cache. - MokaCacheBuilder
manager-moka
Builds aCache
with various configuration knobs. - MokaManager
manager-moka
ImplementsCacheManager
withmoka
as the backend. - Component parts of an HTTP
Request
Enums
- Similar to make-fetch-happen cache options. Passed in when the
HttpCache
struct is being built.
Traits
- A trait providing methods for storing, reading, and removing cache records.